﻿//创建人：zhangrj
//日期：2021-12-17
//描述：材料牌号钛合金页面js

var page = {
    pagetotal: 0,
    pageSize: 10,
    pageNumber: 1,
    rootPath: getRootPath(), //网站根路径
    //初始化页面
    init: function () {
        page.bind();
    },
    //页面事件绑定
    bind: function () {
        //列表加载
        $("#gdRecordInfo").datagrid({
            onLoadSuccess: function (data) {
                $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
                customizedEasyuiPagination('pp'); //定制化分页
                //页码跳转事件
                $('#pageGo').on('click', function () {
                    page.pageNumber = $(this).parents('tr').find('.pagination-num').val();
                    page.search();
                });
            },
            columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
		         { field: 'MATERIALTRADEMARK', title: '材料牌号', width: 200 },
                 { field: 'ISTITANIUMNAME', title: '是否钛合金', width: 100 },
                 { field: 'ISTITANIUM', hidden: true },
                 { field: 'FULLNAME', title: '维护人', width: 200 },
                 { field: 'CREATEDATE', title: '维护时间', width: 200 },
                 { field: 'YPTITANIUMMATERIALID', title: '', width: 200, hidden: true }
                ]]
        });
        //分页事件
        $('#pp').pagination({
            onSelectPage: function (pageNumber, pageSize) {
                customizedEasyuiPagination('pp'); //定制化分页
                page.pageSize = pageSize; page.pageNumber = pageNumber;
                page.search();
            }
        });
        //查询按钮事件
        $('#btnSearch').on("click", function () {
            clearMessage();
            $("#gdRecordInfo").datagrid('loading');
            page.pageNumber = 1;
            page.search();
        });
        //保存
        $('#btnSave').on("click", function () {
            page.save();
        })
    },
    //查询
    search: function () {
        var gridID = "#gdRecordInfo";
        var formData = {
            action: "GetPageList",
            pageSize: page.pageSize,
            pageNumber: page.pageNumber,
            materialtrademark: $('#txtMaterialtrademark').textbox('getValue'),
            isTitanium: $('#isTitanium').combobox('getValue')
        };
        $.ajax({
            type: "Post",
            url: page.rootPath + "/Ashx/YePianContainer/YPTitaniumMaterialHandler.ashx",
            data: formData,
            cashe: false,
            success: function (data) {
                $(gridID).datagrid('loaded');
                var result = JSON.parse(data);
                //给分页对象赋值
                page.pagetotal = result.RowCount;
                $(gridID).datagrid('loadData', { total: result.RowCount, rows: result.DBTable });
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    },
    //保存
    save: function () {
        $('#btnSave').linkbutton('disable'); //禁用按钮
        var datas = $("#gdRecordInfo").datagrid('getChecked'); //获取所有勾选的行
        if (datas.length == 0) {
            displayMessage2("未选择需要保存的数据", false, ["btnSave"]);
            return;
        }
        var formData = {};
        formData.action = "Save";
        formData.tableData = JSON.stringify(datas);
        formData.titanium = $('#selTitanium').combobox('getValue');
        $.ajax({
            url: page.rootPath + '/Ashx/YePianContainer/YPTitaniumMaterialHandler.ashx',
            type: 'Post',
            data: formData,
            cashe: false,
            success: function (json) {
                var result = JSON.parse(json);
                if (result.Result) {
                    page.pageSize = 10; page.pageNumber = 1;
                    page.search();
                }
                displayMessage2(result.Message, result.Result, ["btnSave"]);
            },
            error: function () {
                displayMessage2(XMLHttpRequest.responseText, false, ["btnSave"]);
            }
        });
    }
};
page.init();
 